/*
 * Copyright 2014 Will Dignazio
 */

#include <unistd.h>
#include <string.h>
#include <socketio.h>
#include <pthread.h>
#include "internal.h"

SocketSession*
allocsession(void)
{
	SocketSession *session;

	session = NULL;

	session = malloc(sizeof(*session));
	if(session == NULL)
		goto fail;

	return session;
fail:
	if(session != NULL) {
		if(session->sid != NULL)
			free(session->sid);
		free(session);
	}

	return NULL;
}

void
freesession(SocketSession *session)
{
	if(session == NULL)
		return;

	if(session->sid != NULL)
		free(session->sid);

	free(session);
}

int
startsession(char *sid, uint32_t heartbeat_timeout, uint32_t close_timeout, uint32_t transtypes, SocketSession *session)
{
	int ret;

	ret = -1;
	session->sid = malloc(strlen(sid));
	if(session->sid == NULL)
		goto fail;

	strcpy(session->sid, sid);
	session->heartbeat_timeout = heartbeat_timeout;
	session->close_timeout = close_timeout;
	session->transtypes = transtypes;

	ret = 0;
fail:
	return ret;
}
